package com.xuan.web;
import com.xuan.model.User;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@WebFilter(urlPatterns = "/servlet/*")
@SuppressWarnings("all")
public class RightFilter implements Filter {
    public void doFilter(ServletRequest req, ServletResponse resp,
                         FilterChain chain) throws ServletException, IOException {
        //判断是否登录
        User loginEmp = (User) ((HttpServletRequest) req).getSession().getAttribute("loginEmp");
        if(loginEmp!=null){
            chain.doFilter(req, resp);
        }else{
            req.setAttribute("msg","您还没有登录或者登录已经超时。");
            req.getRequestDispatcher("../login.jsp").forward(req,resp);
        }

    }
}
